//
//  UIBarButtonItem+SRExtension.m
//  StockpdfReading
//
//  Created by mac on 2017/7/15.
//  Copyright © 2017年 上海LOL信息技术服务有限公司. All rights reserved.
//

#import "UIBarButtonItem+SRExtension.h"

@implementation UIBarButtonItem (SRExtension)

+(instancetype)itemWithImage:(NSString *)image selectedImage:(NSString *)selectedImage addTarget:(id)target action:(SEL)action{
    UIButton *button = [[UIButton alloc]init];
    [button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:selectedImage] forState:UIControlStateHighlighted];
    button.size = button.currentBackgroundImage.size;
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc]initWithCustomView:button];
}

+(instancetype)itemWithTitle:(NSString *)title addTarget:(id)target action:(SEL)action{
    UIButton *button = [[UIButton alloc]init];
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc]initWithCustomView:button];
}

@end
